import org.example.entity.Calculatepojo;
import org.example.interceptor.RpcInterceptor;
import org.example.service.CalculateService;

import java.io.*;
import java.net.ServerSocket;
import java.net.Socket;

public class serverMain {
    public static void main(String[] args) {
        CalculateService calculateService = (CalculateService) RpcInterceptor.createProxy(new CalculateService());
        int port = 9999;
        // Create a server socket
        try (ServerSocket server = new ServerSocket(port)) {
            {
                while (true) {
                    // 等待客户端链接
                    Socket client = server.accept();
                    ByteArrayOutputStream bos = new ByteArrayOutputStream();
                    DataInputStream in = new DataInputStream(client.getInputStream());
                    DataOutputStream out = new DataOutputStream(client.getOutputStream());
                    //调用计算方法
                    calculateService.calculate(null, in, out, Calculatepojo.class);
                    //client.close();
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }

    }


}
